package com.drojian.operator;

import org.junit.Test;


import java.util.ArrayList;
import java.util.concurrent.Callable;


import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;



public class JustAndFromOperator {
    @Test
    public void Test1(){
        System.out.println("aaa");
        JustAndFromOperator operator = new JustAndFromOperator();
        operator.Test2();
        System.out.println("bbb");
    }
   Observer observer = new Observer<Object>() {
       @Override
       public void onSubscribe(Disposable d) {
           System.out.println("onSubscribe:"+d);
       }

       @Override
       public void onNext(Object o) {
           System.out.println("onNext:"+o);
       }

       @Override
       public void onError(Throwable e) {
           System.out.println("onError:"+e);
       }

       @Override
       public void onComplete() {
           System.out.println("onComplete:");
       }
   };
    private void Test2(){
        //最大10个参数
        Observable.just("1","2").subscribe(observer);
        //无限个参数
        Observable.fromArray("1","2").subscribe(observer);
        //数组
        ArrayList<Object> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        Observable.fromIterable(list).subscribe(observer);
        //回调
        Observable.fromCallable(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                return "xjq";
            }
        }).subscribe(observer);
    }
}
